<?php

namespace Proj\ResManBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Person
 *
 * @ORM\Table(name="person")
 * @ORM\Entity
 */
class Person {

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var \DateTime $creationDate
     * @ORM\Column(name="creation_date", type="datetime", unique=false, nullable=false) 
     */
    private $creationDate;
    
    /**
     * 
     * @var string
     * 
     * @ORM\Column(name="firstname", type="string", length=30, unique=false, nullable=false)
     */
    private $firstname;
    
    /**
     *
     * @var string
     * 
     * @ORM\Column(name="lastname", type="string", length=30, unique=false, nullable=false)
     */
    private $lastname;
    
    /**
     *
     * @var string
     * 
     * @ORM\Column(name="middlename", type="string", length=30, unique=false, nullable=false)
     */
    private $middlename;
    
    /**
     *
     * @var string
     * 
     * @ORM\Column(name="email", type="string", length=255, unique=true, nullable=false)
     */
    private $email;
    
    /**
     *
     * @var string
     * 
     * @ORM\Column(name="address", type="text", unique=false, nullable=true)
     */
    private $address;
    
    /**
     *
     * @var string
     * 
     * @ORM\Column(name="function", type="string", length=100, unique=false, nullable=false)
     */
    private $function;
    
    /**
     * @var Department
     *
     * @ORM\ManyToOne(targetEntity="Department", inversedBy="people")
     * @ORM\JoinColumn(name="depatment_id", referencedColumnName="id")
     */
    private $department;
    
    /**
     *
     * @var string
     * 
     * @ORM\Column(name="other", type="text", unique=false, nullable=true) 
     */
    private $other;
    
    /**
     *
     * @var \Doctrine\Common\Collections\ArrayCollection
     * 
     * @ORM\ManyToMany(targetEntity="Project", mappedBy="people")
     * @ORM\JoinTable(
     *      name="project_people",
     *      joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="project_id", referencedColumnName="id")}
     * )
     */
    private $projects;
    
    /**
     *
     * @var User
     * 
     * @ORM\OneToOne(targetEntity="User", inversedBy="person")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     * 
     */
    private $user;

    /**
     *
     * @var \Doctrine\Common\Collections\ArrayCollection
     * 
     * @ORM\ManyToMany(targetEntity="Task", mappedBy="people")
     * @ORM\JoinTable(
     *      name="task_people",
     *      joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="task_id", referencedColumnName="id")}
     * )
     */
    private $tasks;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set creationDate
     *
     * @param \DateTime $creationDate
     * @return Person
     */
    public function setCreationDate($creationDate)
    {
        $this->creationDate = $creationDate;
    
        return $this;
    }

    /**
     * Get creationDate
     *
     * @return \DateTime 
     */
    public function getCreationDate()
    {
        return $this->creationDate;
    }

    /**
     * Set firstname
     *
     * @param string $firstname
     * @return Person
     */
    public function setFirstname($firstname)
    {
        $this->firstname = $firstname;
    
        return $this;
    }

    /**
     * Get firstname
     *
     * @return string 
     */
    public function getFirstname()
    {
        return $this->firstname;
    }

    /**
     * Set lastname
     *
     * @param string $lastname
     * @return Person
     */
    public function setLastname($lastname)
    {
        $this->lastname = $lastname;
    
        return $this;
    }

    /**
     * Get lastname
     *
     * @return string 
     */
    public function getLastname()
    {
        return $this->lastname;
    }

    /**
     * Set middlename
     *
     * @param string $middlename
     * @return Person
     */
    public function setMiddlename($middlename)
    {
        $this->middlename = $middlename;
    
        return $this;
    }

    /**
     * Get middlename
     *
     * @return string 
     */
    public function getMiddlename()
    {
        return $this->middlename;
    }

    /**
     * Set email
     *
     * @param string $email
     * @return Person
     */
    public function setEmail($email)
    {
        $this->email = $email;
    
        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set address
     *
     * @param string $address
     * @return Person
     */
    public function setAddress($address)
    {
        $this->address = $address;
    
        return $this;
    }

    /**
     * Get address
     *
     * @return string 
     */
    public function getAddress()
    {
        return $this->address;
    }

    /**
     * Set function
     *
     * @param string $function
     * @return Person
     */
    public function setFunction($function)
    {
        $this->function = $function;
    
        return $this;
    }

    /**
     * Get function
     *
     * @return string 
     */
    public function getFunction()
    {
        return $this->function;
    }

    /**
     * Set other
     *
     * @param string $other
     * @return Person
     */
    public function setOther($other)
    {
        $this->other = $other;
    
        return $this;
    }

    /**
     * Get other
     *
     * @return string 
     */
    public function getOther()
    {
        return $this->other;
    }

    /**
     * Set department
     *
     * @param \Proj\ResManBundle\Entity\Department $department
     * @return Person
     */
    public function setDepartment(\Proj\ResManBundle\Entity\Department $department = null)
    {
        $this->department = $department;
    
        return $this;
    }

    /**
     * Get department
     *
     * @return \Proj\ResManBundle\Entity\Department 
     */
    public function getDepartment()
    {
        return $this->department;
    }

    /**
     * Set projects
     *
     * @param \Proj\ResManBundle\Entity\Project $projects
     * @return Person
     */
    public function setProjects(\Proj\ResManBundle\Entity\Project $projects = null)
    {
        $this->projects = $projects;
    
        return $this;
    }

    /**
     * Get projects
     *
     * @return \Proj\ResManBundle\Entity\Project 
     */
    public function getProjects()
    {
        return $this->projects;
    }

    /**
     * Set user
     *
     * @param \Proj\ResManBundle\Entity\User $user
     * @return Person
     */
    public function setUser(\Proj\ResManBundle\Entity\User $user = null)
    {
        $this->user = $user;
    
        return $this;
    }

    /**
     * Get user
     *
     * @return \Proj\ResManBundle\Entity\User 
     */
    public function getUser()
    {
        return $this->user;
    }
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->projects = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add projects
     *
     * @param \Proj\ResManBundle\Entity\Project $projects
     * @return Person
     */
    public function addProject(\Proj\ResManBundle\Entity\Project $projects)
    {
        $this->projects[] = $projects;

        return $this;
    }

    /**
     * Remove projects
     *
     * @param \Proj\ResManBundle\Entity\Project $projects
     */
    public function removeProject(\Proj\ResManBundle\Entity\Project $projects)
    {
        $this->projects->removeElement($projects);
    }

    /**
     * Add tasks
     *
     * @param \Proj\ResManBundle\Entity\Task $tasks
     * @return Person
     */
    public function addTask(\Proj\ResManBundle\Entity\Task $tasks)
    {
        $this->tasks[] = $tasks;

        return $this;
    }

    /**
     * Remove tasks
     *
     * @param \Proj\ResManBundle\Entity\Task $tasks
     */
    public function removeTask(\Proj\ResManBundle\Entity\Task $tasks)
    {
        $this->tasks->removeElement($tasks);
    }

    /**
     * Get tasks
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getTasks()
    {
        return $this->tasks;
    }
    
        public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addPropertyConstraint('department', new NotBlank(array(
            'message' => 'Trebuie sa selectati un departament.'
        )));
        $metadata->addPropertyConstraint('firstname', new NotBlank(array(
            'message' => 'Trebuie sa introduceti numele.'
        )));
        $metadata->addPropertyConstraint('lastname', new NotBlank(array(
            'message' => 'Trebuie sa introduceti prenumele.'
        )));
        $metadata->addPropertyConstraint('email', new NotBlank(array(
            'message' => 'Trebuie sa introduceti adresa de email.'
        )));
        $metadata->addPropertyConstraint('address', new NotBlank(array(
            'message' => 'Trebuie sa introduceti adresa.'
        )));
        $metadata->addPropertyConstraint('function', new NotBlank(array(
            'message' => 'Trebuie sa introduceti functia.'
        )));
    }
}
